//优化 http 处理不同静态文件 css js image,放在不同的目录 css 放于 css 目录下 js放于 js 目录下，image 放于 image 下

let http = require('http');
let fs = require('fs');
let server =http.createServer();

server.on('request',(req,res) => {
    res.setHeader('Content-type','text/html; charset=utf-8');
    console.log(req.url);
        if(req.url === '/html'){
            res.write(fs.readFileSync('./html/1.html'))
        }
        if(req.url === '/css'){
            res.writeHead(200, { 'Content-Type': 'text/css' });
            res.write(fs.readFileSync('./css/2.css'))
        }
        if(req.url === '/img'){
            res.writeHead(200, {'Content-Type': 'image/jpg'});
            res.write(fs.readFileSync('./img/ui.jpg'))
        }

        
    res.end();
})
server.listen(8080);